package activity.video;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import com.hichip.campro.R;
import base.HiActivity;
import common.HiDataValue;
import common.TitleView;

public class SearchSDCardVideoActivity extends HiActivity implements OnClickListener {
	@Override
	protected int setLayoutId() {
		return R.layout.activity_search_sdcard_video;
	}
	@Override
	protected void init(@Nullable Bundle savedInstanceState) {
		initView();
	}
	private void initView() {
		TitleView title = (TitleView) findViewById(R.id.title_top);
		title.setTitle(getResources().getString(R.string.title_search_video));
		title.setButton(TitleView.NAVIGATION_BUTTON_LEFT);
		title.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
			@Override
			public void OnNavigationButtonClick(int which) {
				switch (which) {
					case TitleView.NAVIGATION_BUTTON_LEFT:
						SearchSDCardVideoActivity.this.finish();
						break;
					case TitleView.NAVIGATION_BUTTON_RIGHT:
						break;
				}
			}
		});

		LinearLayout sd_card_hour_ll = (LinearLayout) findViewById(R.id.sd_card_hour_ll);
		sd_card_hour_ll.setOnClickListener(this);
		LinearLayout sd_card_half_day_ll = (LinearLayout) findViewById(R.id.sd_card_half_day_ll);
		sd_card_half_day_ll.setOnClickListener(this);
		LinearLayout sd_card_a_day_ll = (LinearLayout) findViewById(R.id.sd_card_a_day_ll);
		sd_card_a_day_ll.setOnClickListener(this);
		LinearLayout sd_card_week_ll = (LinearLayout) findViewById(R.id.sd_card_week_ll);
		sd_card_week_ll.setOnClickListener(this);
		LinearLayout sd_card_self_ll = (LinearLayout) findViewById(R.id.sd_card_self_ll);
		sd_card_self_ll.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.sd_card_hour_ll: {//一个小时
				Bundle bundle = new Bundle();
				bundle.putLong("START TIME", System.currentTimeMillis() - 60 * 60 * 1000);
				bundle.putLong("END TIME", System.currentTimeMillis());
				Intent intent = new Intent(SearchSDCardVideoActivity.this, VideoActivity.class);
				intent.putExtra(HiDataValue.EXTRAS_KEY_DATA, bundle);
				intent.putExtra("type", 1);
				SearchSDCardVideoActivity.this.setResult(RESULT_OK, intent);
				finish();
			}

			break;
			case R.id.sd_card_half_day_ll: {
				Bundle bundle = new Bundle();
				bundle.putLong("START TIME", System.currentTimeMillis() - 12 * 60 * 60 * 1000);
				bundle.putLong("END TIME", System.currentTimeMillis());
				Intent intent = new Intent(SearchSDCardVideoActivity.this, VideoActivity.class);
				intent.putExtra(HiDataValue.EXTRAS_KEY_DATA, bundle);
				intent.putExtra("type", 2);
				SearchSDCardVideoActivity.this.setResult(RESULT_OK, intent);
				finish();
			}

			break;
			case R.id.sd_card_a_day_ll: {
				Bundle bundle = new Bundle();
				bundle.putLong("START TIME", System.currentTimeMillis() - 24 * 60 * 60 * 1000);
				bundle.putLong("END TIME", System.currentTimeMillis());
				Intent intent = new Intent(SearchSDCardVideoActivity.this, VideoActivity.class);
				intent.putExtra(HiDataValue.EXTRAS_KEY_DATA, bundle);
				intent.putExtra("type", 3);
				SearchSDCardVideoActivity.this.setResult(RESULT_OK, intent);
				finish();
			}

			break;
			case R.id.sd_card_week_ll: {
				Bundle bundle = new Bundle();
				bundle.putLong("START TIME", System.currentTimeMillis() - 7 * 24 * 60 * 60 * 1000);
				bundle.putLong("END TIME", System.currentTimeMillis());
				Intent intent = new Intent(SearchSDCardVideoActivity.this, VideoActivity.class);
				intent.putExtra(HiDataValue.EXTRAS_KEY_DATA, bundle);
				intent.putExtra("type", 4);
				SearchSDCardVideoActivity.this.setResult(RESULT_OK, intent);
				finish();
			}
			break;
			case R.id.sd_card_self_ll:
				Intent intent = new Intent(SearchSDCardVideoActivity.this, ConstomSearchActivity.class);
				startActivityForResult(intent, 110);
				break;
		}

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK && requestCode == 110) {
			data.putExtra("type", 5);
			setResult(RESULT_OK, data);
			finish();
		}
	}

}
